use crate::models::user::User;
use sqlx::MySqlPool;

pub struct UserDao {
    pool: MySqlPool,
}

impl UserDao {
    pub fn new(pool: MySqlPool) -> Self {
        UserDao { pool }
    }

    pub async fn get_all_users(&self) -> Result<Vec<User>, sqlx::Error> {
        let query = "SELECT id, name,email FROM user_info";
        let users = sqlx::query_as::<_, User>(query)
            .fetch_all(&self.pool)
            .await?;
        Ok(users)
    }
}
